import threading
import socket
import dpkt
import time

class NetInjector(threading.Thread):
    def __init__(self,interface):
        ''' Class constructor '''
        threading.Thread.__init__(self)
        self.__running = False
        self.__outputBuffer = []
        self.__interface = interface
        
    
    def bufferLength(self):
        ''' Returns length of buffer '''
        return len(self.__outputBuffer)
    
    def bufferEmpty(self):
        ''' Returns True if the buffer is empty, False otherwise '''
        if self.bufferLength() > 0:
            return False
        else:
            return True
        
    def addToBuffer(self,packet):
        ''' Appends data to the output buffer '''
        self.__outputBuffer.append(packet)
        
    def isRunning(self):
        ''' Returns True if the injector thread is running, otherwise will return False '''
        return self.__running
    
    def stop(self):
        ''' Attempts to stop the injector soflty '''
        self.__running = False
        
    def run(self):
        ''' Main routine '''
        self.__running = True
        while self.isRunning():
            if not self.bufferEmpty():
                pass
            else:
                time.sleep(0.01)